package com.ocean.admin.extension.security;

import com.ocean.admin.extension.security.handler.RestAuthenticationSuccess;
import com.ocean.security.filter.CustomUsernamePasswordAuthenticationFilter;
import com.ocean.security.handler.RestAuthenticationFailureHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;

/**
 * 自定义Security配置
 *
 * @author zhang
 * @since 2023/11/25
 */
@Configuration
public class WebSecurityConfig {

    @Autowired
    private RestAuthenticationSuccess restAuthenticationSuccess;

    @Autowired
    private AuthenticationManager authenticationManager;

    @Bean
    public CustomUsernamePasswordAuthenticationFilter customAuthenticationFilter() {
        CustomUsernamePasswordAuthenticationFilter filter = new CustomUsernamePasswordAuthenticationFilter();
        filter.setAuthenticationSuccessHandler(restAuthenticationSuccess);
        filter.setAuthenticationFailureHandler(new RestAuthenticationFailureHandler());
        filter.setAuthenticationManager(authenticationManager);
        filter.setFilterProcessesUrl("/admin/sys-user/login");
        return filter;
    }
}
